package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.common.exception.LyException;
import com.leyou.item.dto.SkuDTO;
import com.leyou.item.entity.Sku;
import com.leyou.item.mapper.SkuMapper;
import com.leyou.item.service.SkuService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

@Service
public class SkuServiceImpl extends ServiceImpl<SkuMapper, Sku> implements SkuService {
    @Override
    public List<SkuDTO> listSkuByIds(List<Long> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            throw new LyException(400, "sku的查询Id集合不能为空");
        }
        return SkuDTO.convertEntityList(listByIds(ids));
    }

    @Override
    public List<SkuDTO> listSkuBySpu(Long spuId) {

        return SkuDTO.convertEntityList(this.query().eq("spu_id", spuId).list());
    }
}
